﻿/*********************************************************************
 版权所有: 版权所有(C) 2009 ,熙软研发部
 模块编号:  AutoSmSend.aspx
 作    者:范徐超
 编写日期:2009-09-10
 审    核:
 审核日期:
 描    述:短信服务页
...........................................................................
如果模块有修改，则每次修改添加以下注释(以系统上线后为基准)：

 *********************************************************************/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;


using Cisoft.EMA.BLL;
using Cisoft.EMA.Model;
using Cisoft.Booking.Model;
using Cisoft.Booking.BLL;

public partial class AutoScan_AutoSmSend : WebUI.Page.SendMessagePage
{
    private SMS_InboxBO inboxBO = new SMS_InboxBO();
    private SMS_OutBox outboxBO = new SMS_OutBox();
    private SMS_OutboxMO outboxMO = new SMS_OutboxMO();
    private RuleBO ruleBO = new RuleBO();
    private RuleMO ruleMO = new RuleMO();
    private ShortMessageBO smBO = new ShortMessageBO();
    private ShortMessageMO smMO = new ShortMessageMO();

    #region 页面加载事件
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label2.Text = "";
            Label7.Text = "";
            Label1.Text = "";
            textBox1.Text = "1";
            Label4.Text = "";
            LinkButton1.Enabled = true;
            timer1.Enabled = false;

            Label3.Text = GetCanUpdateConfigValue("bookingtime").ToString();

            if (GetCanUpdateConfigValue("bookingtime").ToString() == "")
            {
                //当前时间增加入配置文件
                string tnow = DateTime.Now.ToString();

                //新增配置时间节
                if (ConfigMg.UIConfig.SetConfigKeyValue("appSettings", "bookingtime", tnow) == "修改成功")
                {
                    Label1.Text = tnow;
                    Label2.Text = "获取配置信息成功，请设定服务运行间隔时间，点击启动服务";
                }
                else
                {
                    LinkButton1.Enabled = false;
                    Label2.Text = "配置信息设定失败，服务不能正常启动，请联系管理员";
                }
            }
            else
            {
                string wrongorright = "ok";
                try
                {
                    DateTime.Parse(GetCanUpdateConfigValue("bookingtime").ToString());
                }
                catch
                {
                    wrongorright = "nook";
                }

                if (wrongorright == "nook")
                {
                    LinkButton1.Enabled = false;
                    Label2.Text = "配置文件中初始时间格式有误，请联系管理员";
                }
                else
                {
                    Label1.Text = GetCanUpdateConfigValue("bookingtime").ToString();
                    Label2.Text = "获取配置信息成功，请设定服务运行间隔时间，点击启动服务";
                }
            }
        }
    }
    #endregion

    #region 按钮事件
    protected void LinkButton1_Click(object sender, EventArgs e)
    {

        Label2.Text = "";

        Label7.Text = "";
        int _time = 1;

        _time = int.Parse(textBox1.Text.Trim().ToString());

        timer1.Interval = _time * 60 * 1000;

        timer1.Enabled = true;

        Label7.Text = "服务运行中[" + DateTime.Now.ToString() + "]..." + "\n\n";

        if (textBox2.Text.ToString() != "")
        {
            Label1.Text = textBox2.Text.ToString();
        }

        GetData(Label1.Text.ToString());
    }
    #endregion

    #region 定时操作具体业务逻辑内容
    /// <summary>
    /// 定时操作具体业务逻辑内容
    /// </summary>
    public void GetData(string strtime)
    {
        //改变订单状态
        ChangeStatus();

        //STEP 1
        //转换成MYSQL 的时间格式
        DateTime dt1 = new DateTime();
        string dt2 = "";
        try
        {
            dt1 = Convert.ToDateTime(strtime);
            dt2 = dt1.ToString().Replace("/", "-");
        }
        catch (Exception ex)
        {
            Response.Write("GetData" + ex.Message);
        }
        //STEP 2
        //根据配置文件中的时间（起点）确定查询短信（经销商发出的短信内容）返回记录
        DataSet dsforup = null;
        DataTable dt = null;
        string strtimemiddle = "";
        int rowCount = 0;
        try
        {
            dsforup = GetListDealerSms(dt2);
            dt = dsforup.Tables[0];
            #region 测试数据

            //DataTable dt = dsforup.Tables[0];
            //DataTable dt = new DataTable();
            //dt = new DataTable();
            //DataColumn dc1 = new DataColumn("EMASMSID");
            //DataColumn dc2 = new DataColumn("EXTCODE");
            //DataColumn dc3 = new DataColumn("SOURCEADDR");
            //DataColumn dc4 = new DataColumn("RECEIVETIME");
            //DataColumn dc5 = new DataColumn("MESSAGECONTENT");
            //DataColumn dc6 = new DataColumn("MSGFMT");
            //DataColumn dc7 = new DataColumn("REQUESTTIME");
            //DataColumn dc8 = new DataColumn("APPLICATIONID");
            //DataColumn dc9 = new DataColumn("ECID");

            //dt.Columns.Add(dc1);
            //dt.Columns.Add(dc2);
            //dt.Columns.Add(dc3);
            //dt.Columns.Add(dc4);
            //dt.Columns.Add(dc5);
            //dt.Columns.Add(dc6);
            //dt.Columns.Add(dc7);
            //dt.Columns.Add(dc8);
            //dt.Columns.Add(dc9);

            //DataRow dr1 = dt.NewRow();
            //object[] ob1 = { System.Guid.NewGuid().ToString(), "", "15307719728", DateTime.Now.ToString(), "DC#A,B#20091204 1700", "15", DateTime.Now.ToString(), "APP014", "defaultema" };
            //dr1.ItemArray = ob1;
            //DataRow dr2 = dt.NewRow();
            //object[] ob2 = { System.Guid.NewGuid().ToString(), "", "15307719728", DateTime.Now.ToString(), "DC#HSPG,HTNM#2#20091130 1722", "15", DateTime.Now.ToString(), "APP014", "defaultema" };
            //dr2.ItemArray = ob2;


            //dt.Rows.Add(dr1);
            //dt.Rows.Add(dr2);
            #endregion
            strtimemiddle = dt1.ToString();
            rowCount = dt.Rows.Count;
        }
        catch
        {
            //Response.Write("GetData STEP2 " + ex.Message);
        }
        if (rowCount > 0)
        {
            //STEP 3
            //展示待发记录条数
            Label4.Text = "待接收短信" + rowCount.ToString() + "条" + "\n\n";

            //STEP4
            //进行循环业务
            for (int i = 0; i < rowCount; i++)
            {
                DataRow dr = dt.Rows[i];
                strtimemiddle = SingleFunction(dr, strtimemiddle, i);
            }

            //STEP 5
            //更新配置文件时间起点函数
            UpdateDateTimeStart(strtimemiddle);
        }
        else
        {
            Label4.Text = "当前没有待接收的订餐短信" + "\n\n";
            Label7.Text = "服务运行中[" + DateTime.Now.ToString() + "]..." + "\n\n";
            return;
        }
    }
    #endregion

    #region 根据配置文件中的时间（起点）获取查询短信（手机发出的内容）返回记录 DataSet GetListGuideSms(string strstart)
    /// <summary>
    /// 根据配置文件中的时间（起点）获取查询短信（手机发出的内容）返回记录 public DataSet GetListGuideSms(string strstart)
    /// </summary>
    /// <param name="strstart"></param>
    /// <returns></returns>
    public DataSet GetListGuideSms(string strstart)
    {
        SMS_InboxBO _smsinbox = new SMS_InboxBO();
        string strWhere = "";

        strWhere += " receivetime > \"" + strstart + "\"";

        return _smsinbox.GetList(strWhere);
    }

    #endregion

    #region 根据配置文件中的时间（起点）确定查询短信（经销商发出的短信内容）返回记录 DataSet GetListDealerSms(string strstart)
    /// <summary>
    /// 根据配置文件中的时间（起点）确定查询短信（经销商发出的短信内容）返回记录 
    /// </summary>
    /// <param name="strstart"></param>
    /// <returns></returns>
    public DataSet GetListDealerSms(string strstart)
    {
        DataSet ds = new DataSet();
        try
        {
            string strWhere = "";

            strWhere += " receivetime > \"" + strstart + "\" and ApplicationID='" + Cisoft.IntegrationSystem.Common.XMLHelper.GetConfigValue("ApplicationID") + "'";

            ds = inboxBO.GetList(strWhere);
        }
        catch //(Exception ex)
        {
            Label4.Text = "远程MySql数据库连接失败，请检查数据库连接字符串！";
        }
        return ds;
    }

    #endregion

    #region 执行写入订单表操作，并回复短信 string SingleFunction(DataRow row, string strtimemiddle,int i)
    /// <summary>
    /// 执行写入订单表操作，并回复短信
    /// </summary>
    /// <param name="dsforup">传入的包含经销商订货数据的DataSet</param>
    /// <param name="strtimemiddle">时间</param>
    /// <param name="i">当前是DataSet的第几条记录</param>
    /// <returns>返回执行插入表和回复短信后的操作后的时间</returns>
    public string SingleFunction(DataRow row, string strtimemiddle, int i)
    {
        Cisoft.EMA.SMS smsyy=new Cisoft.EMA.SMS();


        //根据格式字段进行对应逻辑发送
        if (row["sourceaddr"].ToString() != "")
        {
            //短信内容
            string content = row["MESSAGECONTENT"].ToString();
            //经销商发送号码
            string mobile = row["sourceaddr"].ToString();
            //经销商短信发送时间
            string sendTime = row["receivetime"].ToString();
            //获取smsid
            string smsid = GetEMASMSID(row);

            //STEP 1
            //插入系统短信表
            ArrayList al = GetSMMO(row);
            //Delete(row);

            //预约逻辑
            string strcheck = "";

            if (content.Length > 3)
            {

                strcheck = content.Substring(0, 3);
                if (strcheck == "yy#")
                {
                    string[] strccarray;
                    string allyy = content.Substring(3, content.Length - 3);
                    allyy = allyy.Replace("#", ",");
                    strccarray = Abruption(allyy);
                    if (strccarray.Length == 4)
                    {
                        string strHospitalName = GetHospitalName(strccarray[0]);
                        string strKeShiName = GetKeShiName(strccarray[1]);
                        string strtime = strccarray[2];
                        string stramorpm = strccarray[3];

                        if (strHospitalName == "未知医院名称")
                        {
                            SendMessage(mobile, "未知医院代码,请核对后重试");
                            sms.DeleteRecord(smsid);
                        }
                        else
                        {
                            if (strKeShiName == "未知科室")
                            {
                                SendMessage(mobile, "未知科室代码,请核对后重试");
                                sms.DeleteRecord(smsid);
                            }
                            else
                            {
                                if (Checktime(strtime))
                                {
                                    strtime = strtime.Substring(0, 4) + "-" + strtime.Substring(4, 2) + "-" + strtime.Substring(6, 2);
                                    DateTime a = System.Convert.ToDateTime(strtime);

                                    DateTime ReservationTimeOver = DateTime.Now.AddDays(7);
                                    if (a < DateTime.Now.AddDays(-1) || a > ReservationTimeOver)
                                    {
                                        SendMessage(mobile, "时间超出预约范围。请核对后重试");
                                        sms.DeleteRecord(smsid);
                                    }
                                    else
                                    {
                                        if (stramorpm == "a")
                                        {
                                            string strurl = HttpContext.Current.Server.MapPath("~/xmlconfig/yewutest/yewutestConfiguation.xml");
                                            string strContent = "您已预约" + strHospitalName + "的" + strKeShiName + "。时间为：" + Cisoft.IntegrationSystem.Common.DateTimeHelper.GetChinaShortDateAndWeeky(a) + "上午" + "您前面还有" + Cisoft.IntegrationSystem.Common.XMLHelper.GetConfigValue("Num", strurl) + "位患者。";
                                            SendMessage(mobile, strContent);
                                            sms.DeleteRecord(smsid);
                                            int tnum = int.Parse(Cisoft.IntegrationSystem.Common.XMLHelper.GetConfigValue("Num", strurl).ToString());

                                            if (tnum > 11)
                                            {
                                                tnum = 2;
                                            }
                                            else
                                            {
                                                tnum = tnum + 1;
                                            }

                                            try
                                            {
                                                Cisoft.IntegrationSystem.Common.XMLHelper.SetConfigValue("Num", strurl, tnum.ToString());
                                            }
                                            catch
                                            {

                                            }
                                        }
                                        else
                                        {
                                            if (stramorpm == "b")
                                            {
                                                string strurl = HttpContext.Current.Server.MapPath("~/xmlconfig/yewutest/yewutestConfiguation.xml");
                                                string strContent = "您已预约" + strHospitalName + "的" + strKeShiName + "。时间为：" + Cisoft.IntegrationSystem.Common.DateTimeHelper.GetChinaShortDateAndWeeky(a) + "下午" + "您前面还有" + Cisoft.IntegrationSystem.Common.XMLHelper.GetConfigValue("Num", strurl) + "位患者。";

                                                SendMessage(mobile, strContent);
                                                sms.DeleteRecord(smsid);
                                                int tnum = int.Parse(Cisoft.IntegrationSystem.Common.XMLHelper.GetConfigValue("Num", strurl).ToString());

                                                if (tnum > 11)
                                                {
                                                    tnum = 2;
                                                }
                                                else
                                                {
                                                    tnum = tnum + 1;
                                                }

                                                try
                                                {
                                                    Cisoft.IntegrationSystem.Common.XMLHelper.SetConfigValue("Num", strurl, tnum.ToString());
                                                }
                                                catch
                                                {

                                                }
                                            }
                                            else
                                            {
                                                SendMessage(mobile, "时间格式不对，上午为a下午为b请核对后重试");
                                                sms.DeleteRecord(smsid);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    SendMessage(mobile, "时间格式不正确,应如20090801,请核对后重试");
                                    sms.DeleteRecord(smsid);
                                }
                            }
                        }
                    }
                    else
                    {
                        SendMessage(mobile, "预约格式不正确,请核对后重试");
                        sms.DeleteRecord(smsid);
                    }
                }
            }
           

            //STEP2
            //回复短信
            //if (al.Count >0)
            //{

            //    SendMessage(al[0].ToString(), al[1].ToString());

            //    //STEP3
            //    //把系统回复的短信写入系统短信表
            //    InsertShortMessage(mobile, al[1].ToString());
            //}



            //STEP4
            //更新时间
            if (sendTime != "")
            {
                strtimemiddle = sendTime;
            }
        }
        //Label11.Text = str;
        return strtimemiddle;
    }

    #endregion

    #region 更新配置文件时间起点函数
    public void UpdateDateTimeStart(string strtimemiddle)
    {
        DateTime middletime = DateTime.Parse(strtimemiddle);
        middletime = middletime.AddSeconds(1);
        strtimemiddle = middletime.ToString();

        if (ConfigMg.UIConfig.SetConfigKeyValue("appSettings", "bookingtime", strtimemiddle) == "修改成功")
        {
            Label1.Text = strtimemiddle;
        }
        else
        {
            Label2.Text = "更新配置服务起始时间出现异常，请联系管理员";
        }
    }
    #endregion

    #region 定时操作
    /// <summary>
    /// 定时操作
    /// </summary>
    protected void timer1_Tick(object sender, EventArgs e)
    {
        GetData(Label1.Text.ToString());
    }
    #endregion

    #region 读CanUpdate.config取配置文件 string GetCanUpdateConfigValue(string Target)
    /// <summary>
    /// 读CanUpdate.config取配置文件
    /// </summary>
    /// <param name="Target"></param>
    /// <returns></returns>
    public string GetCanUpdateConfigValue(string Target)
    {
        string path = HttpContext.Current.Server.MapPath("~/xmlconfig/sys/CanUpdate.config");

        XmlDocument doc = loadConfigDocument(path);

        XmlElement root = doc.DocumentElement;
        XmlNodeList elemList = root.GetElementsByTagName("appSettings");

        //重新取得   节点名   
        XmlNode node = doc.SelectSingleNode("//" + "appSettings");
        if (node == null)
            throw new InvalidOperationException("appSettings" + "   section   not   found   in   config   file.");

        try
        {
            //   用   'add'元件   格式化是否包含键名     
            //   select   the   'add'   element   that   contains   the   key   
            XmlElement elem = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", Target));
            string r = elem.Attributes["value"].Value.ToString();
            return r;
        }
        catch (Exception ex)
        {
            string ee = ex.Message.ToString();
            return "";
        }
        //return "";
    }

    #region 读入配置文件 public XmlDocument loadConfigDocument(string url)
    ///   <summary>   
    ///   读入配置文件   
    ///   </summary>   
    public XmlDocument loadConfigDocument(string url)
    {
        XmlDocument doc = null;
        try
        {
            doc = new XmlDocument();
            doc.Load(url);
            return doc;
        }
        catch (System.IO.FileNotFoundException e)
        {
            throw new Exception("No   configuration   file   found.(没有找到配置文件)", e);
        }
    }
    #endregion
    #endregion

    #region 根据分隔符获取短信发送类型
    /// <summary>
    /// 根据分隔符获取短信发送类型
    /// </summary>
    /// <param name="dr">传入的数据行</param>
    private string GetSMType(DataRow dr)
    {
        string str = "";
        //if (dr["messagecontent"].ToString() != "")
        //{
        //    ruleMO = ruleBO.GetModel(" RuleCode = '" + RuleCode + "'");

        str = dr["messagecontent"].ToString();
        if (str.IndexOf("#") >= 0)
        {
            str = str.Split('#')[0].ToString();
        }
        //}
        return str;
    }
    #endregion

    #region 订餐业务逻辑
    #region 遍历短信，分类写入系统短信表 ArrayList GetSMMO(DataRow dr)
    private ArrayList GetSMMO(DataRow dr)
    {
        ArrayList al = new ArrayList();
        object[] objsReturn = new object[4];
        DataSet ds = ruleBO.GetAllList();
        //遍历规则表
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            //短信发送类型
            string strType = GetSMType(dr);
            if (strType != row["RuleCode"].ToString())
            {
                continue;
            }
            //短信发送号码
            string mobile = dr["sourceaddr"].ToString();
            //短信发送时间
            string sendTime = dr["receivetime"].ToString();
            //短信发送内容
            string smContent = dr["messagecontent"].ToString();
            //短信回复内容
            string strReply = row["RuleReply"].ToString();

            if (row["RuleCode"].ToString() == strType)
            {


                #region 订餐
                //如果是订餐
                if (strType == "DC")
                {
                    SetBO setBLL = new SetBO();
                    DishBO dishBLL = new DishBO();
                    //object[] send = { strType, mobile, "系统", dr["messagecontent"].ToString() };
                    object[] send = { "订餐", mobile, "系统", dr["messagecontent"].ToString() };
                    //如果是订餐没有份数
                    if (smContent.Split(Convert.ToChar(GetBreakSymbol("DC"))).Length == 3)
                    {
                        //订餐代码#菜式或套餐代码#用餐时间   ---------默认一份
                        #region 默认一份
                        ////套餐名称
                        string setName = "";
                        //短信订餐内容
                        string orderContent = GetDC(smContent, "DC")[1].ToString();
                        string eatTime = "";
                        //获取用餐时间,格式不正确发送短信提醒正确格式
                        try
                        {
                            eatTime = GetDateTime(GetDC(smContent, "DC")[2].ToString());
                        }
                        catch
                        {
                            SendSMSAndWriteSysMsg(mobile, "短信时间格式不正确！正确格式应为 年月日 时分。例如：20091010 1200");
                            break;
                        }
                        //判断是否有该套餐
                        List<string> listforCode = new List<string>();
                        //遍历代码串
                        foreach (string s in orderContent.Split(','))
                        {
                            //判断是否为套餐
                            string isSetName = setBLL.GetSetNameByCode(s);
                            //判断是否为菜式
                            string isDishName = dishBLL.GetDishNameByCode(s);
                            if (string.IsNullOrEmpty(isSetName) && string.IsNullOrEmpty(isDishName))
                            {
                                listforCode.Add(s);
                            }
                        }
                        if (listforCode.Count > 0)
                        {
                            string errorCode = string.Join(",", listforCode.ToArray());
                            SendSMSAndWriteSysMsg(mobile, "不存在代码为：" + errorCode + "的套餐或菜式，请确认其代码是否正确！");
                            break;
                        }


                        //判断是否超过当前时间
                        try
                        {
                            if (DateTime.Now >= Convert.ToDateTime(eatTime))
                            {
                                SendSMSAndWriteSysMsg(mobile, "用餐时间必须大于当前时间！");
                                break;
                            }
                        }
                        catch
                        {
                            continue;
                        }

                        //设置正确的套餐名称
                        //setName = setBLL.GetSetNames(setBLL.GetSetCodes(orderContent)) + dishBLL.GetDishNames(dishBLL.GetDishCodes(orderContent)) ;
                        List<string> listforName = new List<string>();
                        //遍历代码串
                        foreach (string s in orderContent.Split(','))
                        {
                            //判断是否为套餐
                            string isSetName = setBLL.GetSetNameByCode(s);
                            //判断是否为菜式
                            string isDishName = dishBLL.GetDishNameByCode(s);
                            if (!string.IsNullOrEmpty(isSetName) || !string.IsNullOrEmpty(isDishName))
                            {
                                listforName.Add(string.IsNullOrEmpty(isSetName) ? isDishName : isSetName);
                            }
                        }
                        if (listforName.Count > 0)
                        {
                            setName = string.Join(",", listforName.ToArray());
                        }
                        //回复
                        if (InsertShortMessage(send) > 0)
                        {
                            string isMore = (orderContent.Split(',').Length) > 1 ? "各" : "";
                            //套餐名
                            al.Add(mobile);
                            al.Add(strReply.Replace("[套餐名]", setName + isMore + " 1份").Replace("[时间]", eatTime));
                            //写入系统订单表
                            if (Convert.ToDateTime(eatTime) > DateTime.Now)
                            {
                                OrderAdd(mobile, send[0].ToString(), Convert.ToDateTime(sendTime), "预定[" + setName + "]" + isMore + " 1份,用餐时间为" + eatTime, "", Convert.ToDateTime(eatTime), 1);
                            }
                            break;
                        }
                        #endregion
                    }
                    //如果是订餐有份数
                    if (smContent.Split(Convert.ToChar(GetBreakSymbol("DC"))).Length == 4)
                    {
                        //订餐代码#菜式或套餐代码#份数#用餐时间     ------默认多份
                        #region 默认多份
                        //获取分隔符
                        Char breakSymbol = Convert.ToChar(GetBreakSymbol("DC"));
                        string[] strsSmsContent = smContent.Split(breakSymbol);
                        //获取订餐代码
                        string dcCode = strsSmsContent[0].ToString();
                        //获取订餐份数
                        string dcCount = strsSmsContent[2].ToString();
                        //获取订餐菜式或套餐代码
                        string dcSetOrDishCode = strsSmsContent[1].ToString();
                        //获取用餐时间
                        string dcEatTime = strsSmsContent[3].ToString();


                        ////套餐名称
                        string setName = "";
                        //短信订餐内容
                        string orderContent = GetDC(smContent, "DC")[1].ToString();
                        string eatTime = "";
                        //获取用餐时间,格式不正确发送短信提醒正确格式
                        try
                        {
                            eatTime = GetDateTime(dcEatTime);
                        }
                        catch
                        {
                            SendSMSAndWriteSysMsg(mobile, "短信时间格式不正确！正确格式应为 年月日 时分。例如：20091010 1200");
                            break;
                        }
                        //判断是否有该套餐或菜式
                        //string errorSetStrings = setBLL.GetErrorSetString(setBLL.GetErrorSetCodes(orderContent));
                        //string errorDishStrings = dishBLL.GetErrorDishString(dishBLL.GetErrorDishCodes(orderContent));
                        //if (!string.IsNullOrEmpty(errorSetStrings) || !string.IsNullOrEmpty(errorDishStrings))
                        //{
                        //    string stringError = errorSetStrings + errorDishStrings;
                        //    SendSMSAndWriteSysMsg(mobile, "不存在代码为：" + stringError.TrimEnd(',').TrimStart(',') + "的套餐或菜式，请确认其代码是否正确！");
                        //    break;
                        //}
                        List<string> listforCode = new List<string>();
                        //遍历代码串
                        foreach (string s in orderContent.Split(','))
                        {
                            //判断是否为套餐
                            string isSetName = setBLL.GetSetNameByCode(s);
                            //判断是否为菜式
                            string isDishName = dishBLL.GetDishNameByCode(s);
                            if (string.IsNullOrEmpty(isSetName) && string.IsNullOrEmpty(isDishName))
                            {
                                listforCode.Add(s);
                            }
                        }
                        if (listforCode.Count > 0)
                        {
                            string errorCode = string.Join(",", listforCode.ToArray());
                            SendSMSAndWriteSysMsg(mobile, "不存在代码为：" + errorCode + "的套餐或菜式，请确认其代码是否正确！");
                            break;
                        }
                        //判断是否超过当前时间
                        try
                        {
                            if (DateTime.Now >= Convert.ToDateTime(eatTime))
                            {
                                SendSMSAndWriteSysMsg(mobile, "用餐时间必须大于当前时间！");
                                break;
                            }
                        }
                        catch
                        {
                            continue;
                        }

                        //设置正确的套餐名称
                        List<string> listforName = new List<string>();
                        //遍历代码串
                        foreach (string s in orderContent.Split(','))
                        {
                            //判断是否为套餐
                            string isSetName = setBLL.GetSetNameByCode(s);
                            //判断是否为菜式
                            string isDishName = dishBLL.GetDishNameByCode(s);
                            if (!string.IsNullOrEmpty(isSetName) || !string.IsNullOrEmpty(isDishName))
                            {
                                listforName.Add(string.IsNullOrEmpty(isSetName) ? isDishName : isSetName);
                            }
                        }
                        if (listforName.Count > 0)
                        {
                            setName = string.Join(",", listforName.ToArray());
                        }
                        //setName = setBLL.GetSetNames(setBLL.GetSetCodes(orderContent)) + dishBLL.GetDishNames(dishBLL.GetDishCodes(orderContent));

                        //回复
                        if (InsertShortMessage(send) > 0)
                        {
                            string isMore = (orderContent.Split(',').Length) > 1 ? "各" : "";
                            //套餐名
                            al.Add(mobile);
                            al.Add(strReply.Replace("[套餐名]", setName + " " + isMore + " " + dcCount + "份").Replace("[时间]", eatTime));
                            //写入系统订单表
                            if (Convert.ToDateTime(eatTime) > DateTime.Now)
                            {
                                OrderAdd(mobile, send[0].ToString(), Convert.ToDateTime(sendTime), "预定[" + setName + "] " + isMore + " " + dcCount + "份,用餐时间为" + eatTime, "", Convert.ToDateTime(eatTime), int.Parse(dcCount));
                            }
                            break;
                        }
                        #endregion
                    }
                }
                #endregion
                #region 取消订餐
                //取消订餐
                if (strType == "QXDC")
                {
                    object[] send = { "取消订餐", mobile, "系统", "取消订餐" };
                    //if (InsertShortMessage(mobile, "取消订餐") > 0)
                    if (InsertShortMessage(send) > 0)
                    {
                        //如果发送取消订餐的时间在用餐时间之前
                        OrderBO obo = new OrderBO();
                        OrderMO omo = new OrderMO();

                        DataSet dsfororder = obo.GetList(" OrderTime >= '" +
                            DateTime.Now.AddHours(-DateTime.Now.Hour).ToString() + "' and OrderTime<= '" +
                            DateTime.Now.AddHours(24 - DateTime.Now.Hour).ToString() + "' and OrderMan='" + mobile + "' and OrderStatus='' and OrderType='DC'");
                        //修改订餐状态
                        if (dsfororder.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow drfororder in dsfororder.Tables[0].Rows)
                            {
                                if (drfororder["OrderStatus"].ToString() == "")
                                {
                                    omo = obo.GetModel(Convert.ToInt32(drfororder["OrderID"].ToString()));
                                    if (omo != null)
                                    {
                                        //设置订单状态为已经取消
                                        omo.OrderStatus = "1";
                                        if (obo.Update(omo) > 0)
                                        {
                                            SendSMSAndWriteSysMsg(mobile, "您的订餐已成功取消");
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            SendSMSAndWriteSysMsg(mobile, "没有找到您的订餐信息或者您的订餐信息已过期。");
                            break;
                        }
                        break;
                    }
                }
                #endregion
                #region 包厢预定
                //包厢预定
                if (strType == "YD")
                {
                    BoxesBO bBO = new BoxesBO();
                    BoxesMO bMO = new BoxesMO();

                    OrderBO oBO = new OrderBO();
                    OrderMO oMO = new OrderMO();

                    DateTime eatTime = new DateTime();
                    bool isRightDate = false;

                    //获取预定包厢的分隔符
                    char breaksymbol = Convert.ToChar(GetBreakSymbol("YD"));
                    //获取短信里的包厢代码
                    string[] contents = dr["messagecontent"].ToString().Split(breaksymbol);
                    string boxcode = contents[1].ToString();
                    //根据包厢代码获取包厢名称
                    string boxname = new BoxesBO().GetBoxNameByCode(boxcode);
                    //获取订包厢用餐时间
                    try
                    {
                        eatTime = Convert.ToDateTime(GetDateTime(contents[2].ToString()));
                        isRightDate = true;
                    }
                    catch
                    {
                        SendMessage(mobile, "日期格式不正确!");
                        break;
                    }
                    if (isRightDate)
                    {
                        //判断短信里的包厢代码是否在现有包厢中
                        if (BoxIsExsistByBoxCode(boxcode))
                        {
                            strReply = strReply.Replace("用餐时间", eatTime.ToString("MM-dd hh:mm")).Replace("包厢名称", boxname);
                            object[] obs = { strType, mobile, "系统", dr["messagecontent"].ToString() };
                            //写入系统短信表
                            if (InsertShortMessage(obs) > 0)
                            {
                                //写入系统订单表
                                //if (OrderAdd(mobile, strType, Convert.ToDateTime(sendTime), "预定包厢[" + boxname + "],用餐时间为[" + GetDateTime(contents[2].ToString()) + "]",Convert.ToDateTime(eatTime)) > 0)
                                if (OrderAdd(mobile, strType, Convert.ToDateTime(sendTime), "预定包厢[" + boxname + "],用餐时间为[" + eatTime.GetDateTimeFormats('f')[0].ToString() + "]", eatTime, 1) > 0)
                                {
                                    //回复订包厢成功短信


                                    if (SendMessageWithRecord(mobile, strReply) > 0)
                                    {
                                        //将回复内容写入系统短信表
                                        InsertShortMessage(mobile, strReply);
                                    }
                                    else
                                    {
                                        throw new Exception("回复出错！");
                                    }
                                }
                            }
                        }
                        else
                        {
                            SendSMSAndWriteSysMsg(mobile, "该包厢不存在，请检查包厢代码是否正确！");
                            break;
                        }
                    }
                    break;
                }
                #endregion
                #region 取消包厢预定
                //取消包厢预定
                if (strType == "QXYD")
                {
                    OrderBO obo = new OrderBO();
                    OrderMO omo = new OrderMO();

                    //搜索订单表,查看该号码是否存在订包厢记录
                    DataSet dsforbox = obo.GetList(" OrderMan='" + mobile + "' and UseTime>'" + DateTime.Now.ToString() + "' and OrderType='YD' and OrderStatus=''");
                    //如果存在,判断取消包厢预定的短信是否在该订包厢的用餐时间之前
                    if (dsforbox.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow drforbox in dsforbox.Tables[0].Rows)
                        {
                            if (drforbox["OrderStatus"].ToString() == "")
                            {
                                omo = obo.GetModel(Convert.ToInt32(drforbox["OrderID"].ToString()));
                                omo.OrderStatus = "1";
                            }
                        }
                        //回复系统短信
                        SendSMSAndWriteSysMsg(mobile, strReply);
                    }
                    break;
                }
                #endregion
                #region 投票
                //投票
                if (strType == "TP")
                {
                    ShortMessageStatusBO smsBO = new ShortMessageStatusBO();
                    ShortMessageStatusMO smsMO = new ShortMessageStatusMO();
                    //获取投票分隔符
                    char breakSymbol = Convert.ToChar(GetBreakSymbol("TP"));
                    //如果短信里的投票分隔符与规则表里的一致
                    if (smContent.IndexOf(breakSymbol) > 0)
                    {
                        string[] strContents = null;
                        int voteid = 0;
                        int voteoptionnumber = 0;
                        try
                        {
                            //使用分隔符分隔短信内容
                            strContents = smContent.Split(breakSymbol);
                            //取出投票ID
                            voteid = int.Parse(strContents[1].ToString());
                            //取出投票选项
                            voteoptionnumber = int.Parse(strContents[2].ToString());
                        }
                        catch
                        {

                        }
                        //判断是否存在该投票
                        bool voteIsExsist = false;
                        foreach (DataRow drforvote in new Cisoft.Booking.BLL.VoteBO().GetAllList().Tables[0].Rows)
                        {
                            if (strContents[1].ToString() == drforvote["VoteID"].ToString())
                            {
                                voteIsExsist = true;
                                break;
                            }
                        }
                        if (voteIsExsist)
                        {
                            //判断投票时间是否过期
                            VoteBO vBO = new VoteBO();
                            VoteMO vMO = new VoteMO();

                            vMO = vBO.GetModel(Convert.ToInt32(strContents[1].ToString()));
                            if (Convert.ToDateTime(sendTime) >= Convert.ToDateTime(vMO.VoteStartTime) && Convert.ToDateTime(sendTime) <= Convert.ToDateTime(vMO.VoteEndTime))
                            {
                                //判断是否已经投过票(遍历短信表，找到相同记录)
                                bool voteIsRepeate = false;
                                DataSet dsforsm = smBO.GetList(" ShortMessageType like '%TP%' and ShortMessageSend= '" + mobile + "'");
                                if (dsforsm.Tables[0].Rows.Count > 0)
                                {
                                    foreach (DataRow drforsm in dsforsm.Tables[0].Rows)
                                    {
                                        if (drforsm["ShortMessageContent"].ToString().IndexOf(strContents[0].ToString() + breakSymbol + strContents[1].ToString() + breakSymbol) >= 0)
                                        {
                                            voteIsRepeate = true;
                                            break;
                                        }
                                    }
                                }
                                if (voteIsRepeate)
                                {
                                    SendSMSAndWriteSysMsg(mobile, "您已投过票，请不要重复投票！");
                                    break;
                                }
                                //判断是否存在该选项
                                bool voteOptionIsExsist = false;
                                foreach (DataRow drforvoteoption in new Cisoft.Booking.BLL.VoteOptionBO().GetAllList().Tables[0].Rows)
                                {
                                    if (strContents[2].ToString() == drforvoteoption["VoteOptionNumber"].ToString() && strContents[1].ToString() == drforvoteoption["VoteID_FK"].ToString())
                                    {
                                        voteOptionIsExsist = true;
                                        break;
                                    }
                                }

                                if (voteOptionIsExsist)
                                {
                                    //写入系统短信表
                                    //object[] send = { strType, mobile, "系统", dr["messagecontent"].ToString() };
                                    object[] send = { "投票", mobile, "系统", dr["messagecontent"].ToString() };
                                    if (InsertShortMessage(send) > 0)
                                    {
                                        //更新系统投票表(投票选项计数器)
                                        VoteOptionMO voMO = new VoteOptionMO();
                                        VoteOptionBO voBO = new VoteOptionBO();
                                        voMO = voBO.GetModel(voteid, voteoptionnumber);
                                        if (voMO != null)
                                        {
                                            voMO.VoteCount += 1;
                                            voBO.Update(voMO);
                                            //回复投票成功短信
                                            if (SendMessageWithRecord(mobile, strReply) > 0)
                                            {
                                                //系统短信表
                                                InsertShortMessage(mobile, strReply);
                                            }
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    SendSMSAndWriteSysMsg(mobile, "不存在该投票选项！");
                                    break;
                                }
                            }
                            else
                            {
                                SendSMSAndWriteSysMsg(mobile, "投票已结束,谢谢您的大力支持!");
                                break;
                            }
                        }
                        //如果不存在,发送错误提示短信
                        else
                        {
                            SendSMSAndWriteSysMsg(mobile, "投票代码为[" + strContents[1].ToString() + "]的投票不存在，请确认是否存在该投票！");
                            break;
                        }
                    }
                    break;
                }
                #endregion
                #region 意见
                if (strType == "YJ")
                {
                    string[] yjcontents = smContent.Split(Convert.ToChar(GetBreakSymbol("YJ")));

                    if (yjcontents[1].ToString().Trim() != "")
                    {
                        AdviceBO abo = new AdviceBO();
                        AdviceMO amo = new AdviceMO();

                        amo.AdviceID = abo.GetMaxId();
                        amo.Advice = yjcontents[1].ToString();

                        CustomersBO cbo = new CustomersBO();
                        CustomersMO cmo = new CustomersMO();

                        DataSet dsforcbo = cbo.GetList(" CustomerMobile = '" + mobile + "'");
                        if (dsforcbo.Tables[0].Rows.Count > 0)
                        {
                            amo.CustomerID_FK = int.Parse(dsforcbo.Tables[0].Rows[0]["CustomerID"].ToString());
                        }
                        else
                        {
                            amo.CustomerID_FK = int.Parse(mobile);
                        }
                        //插入意见
                        try
                        {
                            object[] send = { "意见", mobile, "系统", yjcontents[1].ToString() };
                            if (InsertShortMessage(send) > 0)
                            {
                                if (abo.Add(amo) > 0)
                                {
                                    SendSMSAndWriteSysMsg(mobile, "您的意见已经成功发送，感谢您的大力支持！");
                                }
                            }
                        }
                        catch
                        {

                        }
                    }
                }
                #endregion

                //写入短信其他表
                object[] smsOther = { "其他", mobile, "系统", dr["messagecontent"].ToString() };
                InsertShortMessage(smsOther);
            }
            //写入短信失败表
            else
            {
                object[] smsOther = { "处理失败", mobile, "系统", dr["messagecontent"].ToString() };
                InsertShortMessage(smsOther);
            }
        }
        return al;
    }

    #region 根据包厢代码判断是否存在该包厢 bool BoxIsExsistByBoxCode(string BoxCode)
    /// <summary>
    /// 根据包厢代码判断是否存在该包厢
    /// </summary>
    /// <param name="BoxCode">需要判断的包厢代码</param>
    private bool BoxIsExsistByBoxCode(string BoxCode)
    {
        bool flag = false;
        DataSet ds = new BoxesBO().GetAllList();
        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr["BoxesCode"].ToString() == BoxCode)
                {
                    flag = true;
                    break;
                }
            }
        }
        return flag;
    }
    #endregion

    #region 获取分隔符
    /// <summary>
    /// 获取订餐分隔符
    /// </summary>
    /// <param name="Content">短信内容</param>
    /// <param name="Content">规则代码</param>
    /// <returns></returns>
    private string[] GetDC(string Content, string RuleCode)
    {
        ruleMO = ruleBO.GetModel(" RuleCode = '" + RuleCode + "'");
        string[] str = null;
        if (ruleMO != null)
        {
            if (Content.IndexOf(ruleMO.RuleBreakSymbol) >= 0)
            {
                str = Content.Split(ruleMO.RuleBreakSymbol.ToCharArray()[0]);
                string type = str[0].ToString();
                string set = str[1].ToString();
                string time = str[2].ToString();
            }
        }
        return str;
    }

    /// <summary>
    /// 获取投票分隔符
    /// </summary>
    /// <param name="Content">规则代码</param>
    /// <returns></returns>
    private string GetBreakSymbol(string RuleCode)
    {
        ruleMO = ruleBO.GetModel(" RuleCode = '" + RuleCode + "'");
        string str = null;
        if (ruleMO != null)
        {
            str = ruleMO.RuleBreakSymbol;
        }
        return str;
    }
    #endregion

    #region 从字符串中转换日期格式
    /// <summary>
    /// 从字符串中转换日期格式
    /// </summary>
    /// <param name="input">日期字符串</param>
    private string GetDateTime(string input)
    {
        string yyyy = input.Substring(0, 4);
        string MM = input.Substring(4, 2);
        string dd = input.Substring(6, 2);
        string hh = input.Substring(9, 2);
        string mm = input.Substring(11, 2);

        string str = String.Format("{0}年{1}月{2}日{3}:{4}", yyyy, MM, dd, hh, mm);

        return str;
    }
    #endregion

    #endregion

    #region 使用异常判读是否为时间 bool IsTime(string input)
    /// <summary>
    /// 使用异常判读是否为时间
    /// </summary>
    /// <param name="input"></param>
    private bool IsTime(string input)
    {
        bool flag = false;
        try
        {
            Convert.ToDateTime(GetDateTime(input));
            flag = true;
        }
        catch
        {
            flag = false;
        }
        return flag;
    }
    #endregion
    #endregion

    #region 写入系统短信表
    /// <summary>
    /// 写入系统短信表
    /// </summary>
    /// <param name="_smsoutboxmo"></param>
    new private int InsertShortMessage(string Mobile, string Content)
    {
        int i = 0;
        Cisoft.Booking.Model.ShortMessageMO smMO = new Cisoft.Booking.Model.ShortMessageMO();
        Cisoft.Booking.BLL.ShortMessageBO smBO = new Cisoft.Booking.BLL.ShortMessageBO();

        smMO.ShortMessageID = smBO.GetMaxId();
        smMO.ShortMessageContent = Content;
        smMO.ShortMessageSend = "系统";
        smMO.ShortMessageSendTime = DateTime.Now;
        smMO.ShortMessageRecive = Mobile;
        smMO.ShortMessageType = "系统回复";
        smMO.ID_FK = -1;

        i = smBO.Add(smMO);

        return i;
    }

    /// <summary>
    /// 写入系统短信表
    /// </summary>
    /// <param name="al">ArrayList</param>
    private int InsertShortMessage(object[] al)
    {
        int result = 0;
        if (al != null)
        {
            smMO.ShortMessageID = smBO.GetMaxId();
            smMO.ShortMessageContent = al[3].ToString();
            smMO.ShortMessageRecive = al[2].ToString();
            smMO.ShortMessageSend = al[1].ToString();
            smMO.ShortMessageSendTime = DateTime.Now;
            smMO.ShortMessageType = al[0].ToString();
            smMO.ID_FK = -1;

            result = smBO.Add(smMO);
        }
        return result;
    }
    #endregion

    #region 获取EMASMSID string GetEMASMSID(DataRow dr)
    /// <summary>
    /// 获取EMASMSID
    /// </summary>
    /// <param name="dr">传入的包含了EMASMSID的数据行</param>
    private string GetEMASMSID(DataRow dr)
    {
        string id = "";
        if (dr["EMASMSID"] != null)
        {
            id = dr["EMASMSID"].ToString();
        }
        return id;
    }
    #endregion

    #region 如果sms_inbox表存在该记录，则删除该记录 void Delete(DataRow row)
    /// <summary>
    /// 如果sms_inbox表存在该记录，则删除该记录
    /// </summary>
    /// <param name="row">传入的包含了EMASMSID的数据行</param>
    private void Delete(DataRow row)
    {
        try
        {
            if (row[0].ToString() != null)
            {
                string emasmsid = GetEMASMSID(row);

                sms.DeleteRecord(emasmsid);
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
    #endregion

    #region 获取EMA服务器时间
    private DateTime GetEMATime()
    {

        DateTime time = sms.GetEMATime().AddSeconds(10);
        return time;
    }
    #endregion

    #region 写入系统订餐表 void OrderAdd(string man,string OrderType,string OrderTime,string Content,string Status)
    /// <summary>
    /// 写入系统订餐表
    /// </summary>
    /// <param name="man">订餐人</param>
    /// <param name="OrderType">订单类型</param>
    /// <param name="OrderTime">下订单时间</param>
    /// <param name="Content">订单内容</param>
    /// <param name="Status">订单状态</param>
    private void OrderAdd(string man, string OrderType, DateTime OrderTime, string Content, string Status, DateTime UseTime, int OrderCount)
    {
        int result = 0;
        OrderBO oBO = new OrderBO();
        OrderMO oMO = new OrderMO();
        CustomersBO cBO = new CustomersBO();

        oMO.OrderID = oBO.GetMaxId();

        if (cBO.IsEmployee(man))
        {
            oMO.OrderMan = cBO.GetNameByMobile(man) + "/" + man;
        }
        else
        {
            oMO.OrderMan = man;
        }

        oMO.OrderStatus = Status;
        oMO.OrderTime = OrderTime;
        oMO.OrderType = OrderType;
        oMO.OrderContent = Content;
        oMO.UseTime = UseTime;
        oMO.OrderCount = OrderCount;

        try
        {
            result = oBO.Add(oMO);
        }
        catch (Exception ex)
        {
            throw ex;
        }

        if (result > 0)
        {

        }
        else
        {

        }
    }

    private int OrderAdd(string man, string OrderType, DateTime OrderTime, string Content, DateTime UseTime, int OrderCount)
    {
        int result = 0;
        OrderBO oBO = new OrderBO();
        OrderMO oMO = new OrderMO();
        CustomersBO cBO = new CustomersBO();

        oMO.OrderID = oBO.GetMaxId();
        //oMO.OrderMan = man;

        if (cBO.IsEmployee(man))
        {
            oMO.OrderMan = cBO.GetNameByMobile(man);
        }
        else
        {
            oMO.OrderMan = man;
        }

        oMO.OrderStatus = "";
        oMO.OrderTime = OrderTime;
        oMO.OrderType = OrderType;
        oMO.OrderContent = Content;
        oMO.UseTime = UseTime;
        oMO.OrderCount = OrderCount;
        try
        {
            result = oBO.Add(oMO);
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return result;
    }
    #endregion

    #region 发送系统短信并写入系统短信表 void SendSMSAndWriteSysMsg(string mobile,string content,DateTime sendtime)
    /// <summary>
    /// 发送系统短信并写入系统短信表
    /// </summary>
    /// <param name="mobile">手机号码</param>
    /// <param name="content">短信内容</param>
    /// <param name="sendtime">发送时间</param>
    private void SendSMSAndWriteSysMsg(string mobile, string content)
    {
        if (SendMessageWithRecord(mobile, content) > 0)
        {
            InsertShortMessage(mobile, content);
        }
    }
    #endregion

    #region 改变订单状态变为已过期
    private void ChangeStatus()
    {
        OrderBO obo = new OrderBO();
        DataSet ds = obo.GetAllList();
        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                try
                {
                    if (DateTime.Now > Convert.ToDateTime(dr["UseTime"].ToString()))
                    {
                        if (dr["OrderStatus"].ToString().Trim() == "" || dr["OrderStatus"].ToString().Trim() == "1")
                        {
                            OrderMO omo = obo.GetModel(int.Parse(dr["OrderID"].ToString()));
                            if (omo != null)
                            {
                                omo.OrderStatus = "0";
                                obo.Update(omo);
                            }
                        }
                    }
                }
                catch
                {
                    continue;
                }
            }
        }
    }
    #endregion

    #region 根据数字ID返回医院名字
    public string GetHospitalName(string id)
    {
        string hospitalname = "";

        switch (id)
        {
            case "h1":
                hospitalname = "广西医科大学第一附属医院";
                break;
            case "h2":
                hospitalname = "广西壮族自治区人民医院";
                break;
            case "h3":
                hospitalname = "广西医科大学第二附属医院";
                break;
            case "h4":
                hospitalname = "广西中医学院第一附属医院";
                break;
            default:
                hospitalname = "未知医院名称";
                break;
        }

        return hospitalname;
    }
    #endregion

    #region 根据数字ID返回科室名字
    public string GetKeShiName(string id)
    {
        string keshiname = "";

        switch (id)
        {
            case "k1":
                keshiname = "眼科";
                break;
            case "k2":
                keshiname = "儿科";
                break;
            case "k3":
                keshiname = "心血管内科";
                break;
            case "k4":
                keshiname = "神经内科";
                break;
            default:
                keshiname = "未知科室";
                break;
        }

        return keshiname;
    }
    #endregion

    #region 检查时间
    public bool Checktime(string time)
    {
        bool result = true;

        if (isnumber(time) && time.Length==8)
        {
            try
            {
                string strtime = time.Substring(0, 4) + "-" + time.Substring(4, 2) + "-" + time.Substring(6, 2);
                DateTime a = System.Convert.ToDateTime(strtime);
            }
            catch
            {
                return false;
            }

            return result;
        }
        else
        {
            return false;
        }

        return result;
    }
    #endregion

    #region 全为数字
    public bool isnumber(string s)
    {
        int Flag = 0;
        char[] str = s.ToCharArray();
        for (int i = 0; i < str.Length; i++)
        {
            if (Char.IsNumber(str[i]))
            {
                Flag++;
            }
            else
            {
                Flag = -1;
                break;
            }
        }
        if (Flag > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    #endregion
}
